﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MS_UI
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }

        private void OpenWindow(Form form)
        {
            form.TopLevel = false;
            form.FormBorderStyle = FormBorderStyle.None;
            form.Dock = DockStyle.Fill;
            form.Parent = this.panel_Main;
            form.Show();
        }

        private bool CloseWindow(string form)
        {
            foreach (Control ct in this.panel_Main.Controls)
            {
                if(ct is Form)
                {
                    Form frm = (Form)ct;
                    if(frm.Name == form)
                    {
                        return true;
                    }
                    else
                    {
                        frm.Close();
                    }
                }
            }
            return false;
        }

        private void BackColorSet(string str)
        {
            this.btn_View.BackColor = Color.FromArgb(11, 115, 163);
            this.btn_ParamSet.BackColor = Color.FromArgb(11, 115, 163);
            this.btn_Trend.BackColor = Color.FromArgb(11, 115, 163);
            this.btn_Alarm.BackColor = Color.FromArgb(11, 115, 163);
            this.btn_Report.BackColor = Color.FromArgb(11, 115, 163);
            this.btn_HardwareConfig.BackColor = Color.FromArgb(11, 115, 163);
            this.btn_Exit.BackColor = Color.FromArgb(11, 115, 163);
            switch (str)
            {
                case "控制流程":
                    this.btn_View.BackColor = Color.FromArgb(60, 179, 111);
                    break;
                case "参数设置":
                    this.btn_ParamSet.BackColor = Color.FromArgb(60, 179, 111);
                    break;
                case "趋势曲线":
                    this.btn_Trend.BackColor = Color.FromArgb(60, 179, 111);
                    break;
                case "故障报警":
                    this.btn_Alarm.BackColor = Color.FromArgb(60, 179, 111);
                    break;
                case "数据报表":
                    this.btn_Report.BackColor = Color.FromArgb(60, 179, 111);
                    break;
                case "硬件组态":
                    this.btn_HardwareConfig.BackColor = Color.FromArgb(60, 179, 111);
                    break;
                case "Exit":
                    this.btn_Exit.BackColor = Color.FromArgb(60, 179, 111);
                    break;
            }
        }


        private void btn_View_Click(object sender, EventArgs e)
        {
            if (CloseWindow("FrmView")==false)
            {
                OpenWindow(new FrmView());
                lbl_Title.Text = ((Button)sender).Text;
                BackColorSet(((Button)sender).Text);
            }
        }

        private void btn_ParamSet_Click(object sender, EventArgs e)
        {
            if (CloseWindow("FrmParamSet") == false)
            {
                OpenWindow(new FrmParamSet());
                lbl_Title.Text = ((Button)sender).Text;
                BackColorSet(((Button)sender).Text);
            }
        }

        private void btn_Trend_Click(object sender, EventArgs e)
        {
            if (CloseWindow("FrmTrend") == false)
            {
                OpenWindow(new FrmTrend());
                lbl_Title.Text = ((Button)sender).Text;
                BackColorSet(((Button)sender).Text);
            }
        }

        private void btn_Alarm_Click(object sender, EventArgs e)
        {
            if (CloseWindow("FrmAlarm") == false)
            {
                OpenWindow(new FrmAlarm());
                lbl_Title.Text = ((Button)sender).Text;
                BackColorSet(((Button)sender).Text);
            }
        }

        private void btn_Report_Click(object sender, EventArgs e)
        {
            if (CloseWindow("FrmReport") == false)
            {
                OpenWindow(new FrmReport());
                lbl_Title.Text = ((Button)sender).Text;
                BackColorSet(((Button)sender).Text);
            }
        }

        private void btn_HardwareConfig_Click(object sender, EventArgs e)
        {
            if (CloseWindow("FrmHardwareConfig") == false)
            {
                OpenWindow(new FrmHardwareConfig());
                lbl_Title.Text = ((Button)sender).Text;
                BackColorSet(((Button)sender).Text);
            }
        }

        private void btn_Exit_Click(object sender, EventArgs e)
        {
            Application.Exit();
            BackColorSet(((Button)sender).Text);
        }
    

        
    }
}
